#include  <cstdio>
#include  <iostream>
using namespace std;

int n,m,a1,a2,b1,b2,c1,c2,d1,d2;

int g(int n, int x)
{
	if( n < x)
		return 0;
	if( n == x)
		return 1;
	return g(n/5,x) + n/10 + (n%10 >= x);
}

int f(int n, int x)
{
	if(n < x)
		return 0;
	if(n == x)
		return 1;

	return f(n/2,x) + g(n,x);
}

int f1(int n)
{
	if( n <= 1)
		return 0;

	return f1(n/2) + n/2;
}

void search1(int n)
{
	a1 = f(n,3);
	b1 = f(n,7);
	c1 = f(n,9);
	d1 = f1(n);
}

void search2(int n)
{
	a2 = f(n,3);
	b2 = f(n,7);
	c2 = f(n,9);
	d2 = f1(n);
}

int _a[4] = {3,9,7,1};
int _b[4] = {7,9,3,1};
int _c[2] = {9,1};
int _d[4] = {2,4,8,6};

int get5(int n)
{
	if(n == 0 )
		return 0;
	return n/5 + get5(n/5);
}

int main(int argc, char *argv[])
{
	while( scanf("%d%d",&n,&m) != EOF )
	{
		search1(n);
		d1 -= get5(n);
		search2(n-m);
		d2 -= get5(n-m);
		a1 -= a2;
		b1 -= b2;
		c1 -= c2;
		d1 -= d2;
		a1 = a1 > 0 ? _a[(a1-1)%4] : 1;
		b1 = b1 > 0 ? _b[(b1-1)%4] : 1;
		c1 = c1 > 0 ? _c[(c1-1)%2] : 1;
		d1 = d1 > 0 ? _d[(d1-1)%4] : 1;
		int res = a1*b1*c1*d1;
		res %= 10;
		printf("%d\n",res);
	}
}
